<template>
  <el-dialog :visible.sync="dialog"
             :title="title"
             @closed="clearFormData"
             class="apps-tabs-layout"
             width="620px"
             append-to-body>
    <div>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" label-position="left">
        <el-form-item label="Name:" prop="resourceName">
          <el-input v-model="form.resourceName" placeholder="Please Enter The Name"></el-input>
        </el-form-item>
        <div   style="margin-top:20px">
          <el-form-item label="Url:" prop="resourcePath">
            <el-input v-model="form.resourcePath" placeholder="Please Enter The Url"></el-input>
          </el-form-item>
        </div>
      </el-form>
    </div>
    <template slot="footer">
      <el-button size="small"
                 @click="clearFormData">{{ $t('Cancel') }}</el-button>
      <el-button type="primary"
                 size="small"
                 @click="addGadgetToPageGroup(form)">{{ $t('Add') }}</el-button>
    </template>
  </el-dialog>
</template>

<script>
export default {
  props: {
    selectUrlList: {
      type: Array,
      default: () => []
    },
    resourceMenuValue: {
      type: String,
      default: () => ''
    }
  },
  data () {
    return {
      dialog: false,
      title: '',
      form: {
        resourceName: '',
        resourcePath: ''
      },
      rules: {
        resourceName: [
          { required: true, message: 'name is required', trigger: 'blur', pattern: '[^ \x22]+' },
          { validator: this.validatePass, trigger: 'blur' }
        ],
        resourcePath: [
          { required: true, message: 'url is required', trigger: 'blur', pattern: '[^ \x22]+' }
        ]
      }
    }
  },
  methods: {
    validatePass (rule, value, callback) {
      var res = this.selectUrlList.find(i => i.resourceName === value)
      if (res) {
        callback(new Error('The name already exists'))
      } else {
        callback()
      }
    },
    addGadgetToPageGroup (val) {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          if (this.resourceMenuValue === 'report') {
            val.resourceType = 3
            val.resourceMenu = 1
            this.$emit('addUrlToPage', JSON.parse(JSON.stringify(val)))
            this.dialog = false
          } else if (this.resourceMenuValue === 'setting') {
            val.resourceType = 3
            val.resourceMenu = 3
            this.$emit('addUrlToPage', JSON.parse(JSON.stringify(val)))
            this.dialog = false
          }
        } else {
          return false
        }
      })
    },
    clearFormData () {
      this.dialog = false
      this.$refs['form'].resetFields()
    }
  }
}
</script>

<style lang="scss">
.apps-tabs-layout {
  // .select_widget_filter_condition {
  //   background: url("../../../assets/select_widget-filter-icon.png");
  //   background-repeat: no-repeat;
  //   background-position: center left;
  //   background-size: 14px 14px;
  //   padding-left: 20px;
    // .filter_condition_lf {
    //   .filter_condition {
    //     margin-top: 8px;
    //     margin-left: 5px;
    //   }
    // }
    // .filter_condition_lf > div {
    //   float: left;
    //   width: 150px;
    //   margin-right: 10px;
    // }
    // .filter_condition_lf > div:nth-child(1) {
    //   width: auto;
    // }
  // }
  // .select_widget_filter_condition::after {
  //   content: ".";
  //   clear: both;
  //   display: block;
  //   overflow: hidden;
  //   height: 0;
  // }
  .widget_data_list {
    margin-top: 20px;
    min-height: 20px;
    .el-checkbox-group {
      > .is-checked {
        border: 1px solid #138dc7;
      }
    }
    .el-checkbox {
      display: block;
      margin-right: 0;
      background: #ffffff;
      border-radius: 4px;
      border: 1px solid #dcdfe6;
      margin-top: 10px;
      display: flex;
      justify-content: space-around;
      align-items: center;
      .el-checkbox__input {
        display: block;
        width: 54px;
        text-align: center;
      }
      .el-checkbox__label {
        flex: 1;
        display: block;
        height: 100%;
        padding-left: 0;
        .item_widget2 {
          // background: url("~@/assets/grid.png");
          background-size: 48px 48px;
          background-repeat: no-repeat;
          background-position: left center;
          height: 100%;
          padding-left: 54px;
          padding-top: 5px;
          padding-bottom: 5px;
          display: flex;
          justify-content: space-around;
          align-items: center;
          min-height: 70px;
          .item_widget_content {
            flex: 1;
            height: 100%;
            padding-right: 10px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            > div {
              white-space: pre-wrap;
              word-break: break-word;
            }

            > div:nth-child(1) {
              color: #000;
              font-size: 14px;
            }
            > div:nth-child(2) {
              font-size: 14px;
              color: rgba(0, 0, 0, 0.49);
            }
          }
          .item_widget_ri {
            float: right;
            width: 53px;
            height: 100%;
            text-align: center;
            .item {
              height: 14px;
              width: 14px;
              border: 0;
              // background: url("../../../assets/select_widget_eye.png");
              background-size: 14px 14px;
              background-repeat: no-repeat;
              background-position: center;
            }
          }
          position: relative;
        }
        // .item_widget::after {
        //   content: "";
        //   clear: both;
        //   display: block;
        //   overflow: hidden;
        //   position: absolute;
        //   right: 53px;
        //   border-right: 1px solid #f0f0f0;
        //   height: 80%;
        // }
      }
    }
    .el-checkbox::after {
      content: ".";
      clear: both;
      display: block;
      overflow: hidden;
      height: 0;
    }
  }
  .el-pagination {
    text-align: center;
  }
  .layoutTitle {
    font-size: 12px;
    word-break: keep-all;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .layoutTitle:hover {
    overflow: visible;
  }

  .vue-grid-item.vue-grid-placeholder {
    background: #f2f8ff;
    border: 1px solid #38f;
    opacity: 1;
  }

  .layoutJSON {
    background: #ddd;
    border: 1px solid black;
    margin-top: 10px;
    padding: 10px;
  }

  .eventsJSON {
    background: #ddd;
    border: 1px solid black;
    margin-top: 10px;
    padding: 10px;
    height: 100px;
    overflow-y: scroll;
  }

  .columns {
    -moz-columns: 120px;
    -webkit-columns: 120px;
    columns: 120px;
  }

  .vue-resizable-handle {
    z-index: 5000;
    position: absolute;
    width: 20px;
    height: 20px;
    bottom: 0;
    right: 0;
    background: url("");
    background-position: bottom right;
    padding: 0 3px 3px 0;
    background-repeat: no-repeat;
    background-origin: content-box;
    box-sizing: border-box;
    cursor: se-resize;
  }

  .editmode:not(.vue-grid-placeholder) {
    border: 1px solid #38f;
    opacity: 0.5;
  }

  .vue-grid-item.resizing {
    opacity: 0.9;
  }

  .vue-grid-item .no-drag {
    height: 100%;
    width: 100%;
  }

  .vue-grid-item .minMax {
    font-size: 12px;
  }

  .vue-grid-item .add {
    cursor: pointer;
  }

  .vue-draggable-handle {
    position: absolute;
    width: 20px;
    height: 20px;
    top: 0;
    left: 0;
    background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'><circle cx='5' cy='5' r='5' fill='#999999'/></svg>")
      no-repeat;
    background-position: bottom right;
    padding: 0 8px 8px 0;
    background-repeat: no-repeat;
    background-origin: content-box;
    box-sizing: border-box;
    cursor: pointer;
  }

  .layout-item {
    text-align: center;
    margin-bottom: 15px;
    padding: 0 5px;
  }

  .layout-item .bottom {
    position: relative;
    margin-top: 15px;
  }

  .layout-item .bottom span {
    display: block;
    float: left;
    width: 50%;
    margin-top: 12px;
    text-align: left;
  }

  .layout-item .bottom button {
    padding-top: 0;
  }

  .top-toolbar {
    position: relative;
    margin-top: -15px;
    height: 35px;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    background-color: #fff;
    margin-left: -15px;
    padding-top: 10px;
    width: calc(100% + 30px);
  }

  .top-toolbar .top-toolbar-title {
    padding-left: 25px;
  }

  .btnBox {
    height: 16px;
    padding: 0px 10px;
    background: #c4ebf3;
    position: absolute;
    top: -15px;
    right: 24px;
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 6px;
  }

  .showBtn {
    font-size: 18px;
    color: #00c4ed;
  }

  .closeBtn {
    font-size: 18px;
    position: absolute;
    top: 8px;
    right: 11px;
  }
}
</style>
<style lang="scss" scoped>
::v-deep .el-dialog__header {
    display: block!important;
}
::v-deep .el-dialog__body {
  padding: 20px!important;
}
.more_text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap!important;
}
</style>
